package seGobangClient.uiSystem3D;
import javax.media.j3d.*;
import javax.vecmath.*;

import com.sun.j3d.utils.universe.*;
import seGobangResources.PathRes;
/**
 *
 * @author plus
 */
public class MainMenuScene3D implements IScene3D{
    private static BranchGroup PGRoot;
    private static BehaviorFactory Behaviors;
    private Behavior StepIn;
    
    private void initBrachGroup(){
        Behaviors=new BehaviorFactory();
        PGRoot=new BranchGroup();
        PGRoot.setCapability(BranchGroup.ALLOW_DETACH);
                
        Transform3D transMain=new Transform3D();
        transMain.set(new Vector3f(0.175f,-0.05f,0f));
            TransformGroup TGMain=new TransformGroup(transMain);
            TGMain.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
            
        TransformGroup [] TGItem={null,null,null,null,null};
        for (int idItem=0; idItem<5; idItem++){                                 //菜单项
            Transform3D transItem=new Transform3D();
                transItem.set(new Vector3f(0f,(float)(0.2-0.05*idItem),-0.6f));
            TGItem[idItem]=new TransformGroup(transItem);
            //Group [] gpItems={new Group(),new Group()};
            try{
                TGItem[idItem].addChild(ObjectFactory.createTexturedSurface(
                    0.15f, 0.04f, new Color3f(1,1,1),0.0f, PathRes.getPath("Texture/MainMenu/"+(idItem+1)+"A")));
                TGItem[idItem].addChild(ObjectFactory.createTexturedSurface(
                    0.15f, 0.04f, new Color3f(1,1,1),1.0f, PathRes.getPath("Texture/MainMenu/"+(idItem+1)+"B")));
            }catch(Exception e){
                e.printStackTrace();
            }
            TGMain.addChild(TGItem[idItem]);
        }
        Transform3D transIndict = new Transform3D();                            //指示标志
        transIndict.set(new Vector3f(-0.065f, 0.195f, -0.58f));
        TransformGroup TGIndict = new TransformGroup(transIndict);
            TGIndict.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        try {
            Plane2D gemIndict=(Plane2D)ObjectFactory.createTexturedSurface(
                    0.02f, 0.02f, new Color3f(1, 1, 1), 0.0f, PathRes.getPath("Texture/MainMenu/Indict"));
            gemIndict.setPickable(false);
            TGIndict.addChild(gemIndict);
        } catch (Exception e) {
            e.printStackTrace();
        }
        TGMain.addChild(TGIndict);
        PGRoot.addChild(TGMain);
        
        Behavior PickMainMenu=Behaviors.createPickMainMenuBehavior(PGRoot, TGMain);
            PickMainMenu.setSchedulingBounds(new BoundingSphere(new Point3d(0d,0d,0d),100));
        PGRoot.addChild(PickMainMenu);
        
        StepIn=Behaviors.createMainMenuStepInBehavior(TGMain);
        StepIn.setSchedulingBounds(new BoundingSphere());
        PGRoot.addChild(StepIn);
        
        PGRoot.compile();
        
    }
    
    public void setUpScene() {
        if (PGRoot==null) initBrachGroup(); else ((BehaviorFactory.MainMenuStepInBehavior)StepIn).reset();
        SceneManager.dashBoardRoot.addChild(PGRoot);
        
        SceneManager.setView(new Vector3f(-40f,10f,-30f),
                new Vector3f((float)(0),(float)(-Math.PI*.65),(float)(0)));
    }

    public void shutDown() {
        PGRoot.detach(); //与主场景脱离
    }
    
}
